package com.lan.springbootdruid.controller;

import com.lan.springbootdruid.entity.City;
import com.lan.springbootdruid.entity.User;
import com.lan.springbootdruid.service.CityService;
import com.lan.springbootdruid.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @author: Lan
 * @date: 2019/5/5 18:42
 * @description:
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @Autowired
    private CityService cityService;

    @GetMapping("/{id}")
    public Map<String, Object> getUserById(@PathVariable("id") int id) {
        User user = userService.getUserById(id);
        City city = cityService.getCityById(id);
        Map<String, Object> map = new HashMap<>(2);
        map.put("user", user);
        map.put("city", city);
        return map;
    }
}
